class SceneRain {
  constructor(viewer) {
    this.viewer = viewer;
    this.rain = null;
  }
  addRain() {
    this.rain = new Cesium.PostProcessStage({
      name: "czm_rain",
      uniforms: {
        angle: 0.2,
        size: 0.5,
        speed: 200,
      },
      fragmentShader:
        "uniform sampler2D colorTexture;\n\
                in vec2 v_textureCoordinates;\n\
                uniform float angle;\n\
                uniform float size;\n\
                uniform float speed;\n\
                float hash(float x) {\n\
                    return fract(sin(x * 133.3) * 13.13);\n\
                }\n\
                void main(void) {\n\
                    float time = czm_frameNumber / speed;\n\
                    vec2 resolution = czm_viewport.zw;\n\
                    vec2 uv = (gl_FragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);\n\
                    vec3 c = vec3(.6, .7, .8);\n\
                    float a = angle;\n\
                    float si = sin(a), co = cos(a);\n\
                    uv *= mat2(co, -si, si, co);\n\
                    uv *= length(uv + vec2(0, 4.9)) * size + 1.;\n\
                    float v = 1. - sin(hash(floor(uv.x * 100.)) * 2.);\n\
                    float b = clamp(abs(sin(20. * time * v + uv.y * (5. / (2. + v)))) - .95, 0., 1.) * 20.;\n\
                    c *= v * b;\n\
                    out_FragColor = mix(texture(colorTexture, v_textureCoordinates), vec4(c, 1), .5);\n\
                }\n\
                ",
    });
    this.viewer.scene.postProcessStages.add(this.rain);
  }
  changeRain(e) {
    const { l, v } = e;
    this.rain.uniforms.speed = v;
  }
  removeRain() {
    if (this.rain) this.viewer.scene.postProcessStages.remove(this.rain);
  }
}
export default SceneRain;
